package com.online.shopping.service.impl;

import com.online.shopping.mapper.TbBrandMapper;
import com.online.shopping.pojo.TbBrand;
import com.online.shopping.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author Rui
 * @version 1.0
 * @date 2020/11/11 16:01
 */
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private TbBrandMapper brandMapper;

    @Override
    public int addBrand( TbBrand brand) {
        return brandMapper.insert(brand);
    }

    @Override
    public int deleteBrand(Long id) {
        return brandMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateBrand(TbBrand brand) {
        return brandMapper.updateByPrimaryKeySelective(brand);
    }

    @Override
    public TbBrand findBrandById(Long id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<TbBrand> findAllBrands() {
        return brandMapper.selectByExample(null);
    }

    @Override
    public Long[] deleteManyBrands(Long[] ids) {
        for (Long id : ids) {
            brandMapper.deleteByPrimaryKey(id);
        }
        return ids;
    }
}
